/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package providers;

import entities.Contentindex;
import entities.dao.DAOContentindex;
import entities.dao.exceptions.PreexistingEntityException;
import entities.dao.exceptions.RollbackFailureException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.transaction.UserTransaction;

/**
 *
 * @author Emmanuel
 */
@Stateless
public class SearchProvider1 implements SearchProvider1Local {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    @PersistenceUnit
    private EntityManagerFactory entityManagerFactory;
    
    public String testCreacionPost()
    {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Contentindex contentIndex = new Contentindex();
        contentIndex.setTermino("EMMA");
        contentIndex.setNr(50);
        DAOContentindex daoContentIndex = new DAOContentindex((UserTransaction)entityManager.getTransaction(), entityManagerFactory);
        try {
            daoContentIndex.create(contentIndex);
        } catch (PreexistingEntityException ex) {
            Logger.getLogger(SearchProvider.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RollbackFailureException ex) {
            Logger.getLogger(SearchProvider.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(SearchProvider.class.getName()).log(Level.SEVERE, null, ex);
        }
        return contentIndex.toString();
    }
    
}
